package start.fly.test.database;

import java.sql.Date;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Driver;
import com.mysql.jdbc.PreparedStatement;



public class databaseTool {
	//登录验证
	   public static  boolean Vertifylogin(String username1,String password1){
		     int id=0;
			try{
				Driver driver=new com.mysql.jdbc.Driver();
				DriverManager.registerDriver(driver);
				Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8","root","usbw");
				String sql="select * from user where username=? and pwd=?";
				PreparedStatement stmt=(PreparedStatement) connection.prepareStatement(sql);
				stmt.setString(1,username1);
				stmt.setString(2, password1);
			   ResultSet  rs=stmt.executeQuery();
			    while(rs.next()){
			 	id=rs.getInt("usernumber");	 
			    }  
			    rs.close();
				stmt.close();
				connection.close();
			}catch(Exception e){
				e.printStackTrace();
			}
			System.out.println(id);
			if(id>0){
				return true;
			}else{
				return false;
			}
	   
	   }
	   //根据usernumber来删除用户的信息
	 public static boolean deleteUserById(String usernumber){
		   int rs = 0;
		 try{
			 Driver driver=new com.mysql.jdbc.Driver();
				DriverManager.registerDriver(driver);
				Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8","root","usbw");
				String sql="delete  from user where usernumber=?";
				PreparedStatement stmt=(PreparedStatement) connection.prepareStatement(sql);
				stmt.setString(1,usernumber);
			   rs=stmt.executeUpdate();
			   stmt.close();
			   connection.close();
		 }catch(Exception e){
			 e.printStackTrace();
		 }
		 if(rs==1){
	    	   return true;
	       }else{
	    	   return false;
	       }
	 }
	   //根据noticeId来删除公告信息
		 public static boolean deletenoticeById(String noticeId){
			   int rs = 0;
			 try{
				 Driver driver=new com.mysql.jdbc.Driver();
					DriverManager.registerDriver(driver);
					Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8","root","usbw");
					String sql="delete  from notice where noticeId=?";
					PreparedStatement stmt=(PreparedStatement) connection.prepareStatement(sql);
					stmt.setString(1,noticeId);
				   rs=stmt.executeUpdate();
				   stmt.close();
				   connection.close();
			 }catch(Exception e){
				 e.printStackTrace();
			 }
			 if(rs==1){
		    	   return true;
		       }else{
		    	   return false;
		       }
		 }
	  //根据reportId来处理用户提交的举报信息
		 public static boolean dealReoprtById(String reportId){
			   int rs = 0;
			 try{
				 Driver driver=new com.mysql.jdbc.Driver();
					DriverManager.registerDriver(driver);
					Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8","root","usbw");
					String sql="update report_manage set reportStatus='已处理' where reportId=?";
					PreparedStatement stmt=(PreparedStatement) connection.prepareStatement(sql);
					stmt.setString(1,reportId);
				   rs=stmt.executeUpdate();
				   stmt.close();
				   connection.close();
			 }catch(Exception e){
				 e.printStackTrace();
			 }
			 if(rs==1){
		    	   return true;
		       }else{
		    	   return false;
		       }
		 }
	   //根据comId来删除用户评价的信息
		 public static boolean deleteCommentById(String comId){
			   int rs = 0;
			 try{
				 Driver driver=new com.mysql.jdbc.Driver();
					DriverManager.registerDriver(driver);
					Connection connection=(Connection) DriverManager.getConnection("jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8","root","usbw");
					String sql="delete  from  user_comment where comId=?";
					PreparedStatement stmt=(PreparedStatement) connection.prepareStatement(sql);
					stmt.setString(1,comId);
				   rs=stmt.executeUpdate();
				   stmt.close();
				   connection.close();
			 }catch(Exception e){
				 e.printStackTrace();
			 }
			 if(rs==1){
		    	   return true;
		       }else{
		    	   return false;
		       }
		 }

			//向个人会员表插入数据
			 public boolean insertToPersonNumber(String username,String pwd,String question,String answer,String safecode,String img,String email){
			 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="insert into user(username,pwd,question,answer,safecode,img,email) values(?,?,?,?,?,?,?)";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,username);
				   preparedStatement.setString(2,pwd);
				   preparedStatement.setString(3,question);
				   preparedStatement.setString(4,answer);
				   preparedStatement.setString(5,safecode);
				   preparedStatement.setString(6,img);
				   preparedStatement.setString(7,email);
				   rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
			 }
	//向个人会员表插入数据
	 public boolean insertToUserNumber(String username,String pwd,String question,String answer,String safecode,String img,String email,String group){
	 int rs = 0;
    DBConn conn=new DBConn();
	 String sql="insert into user(username,pwd,question,answer,safecode,img,email,GroupNumber) values(?,?,?,?,?,?,?,?)";
	 try {
		PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
		  preparedStatement.setString(1,username);
		   preparedStatement.setString(2,pwd);
		   preparedStatement.setString(3,question);
		   preparedStatement.setString(4,answer);
		   preparedStatement.setString(5,safecode);
		   preparedStatement.setString(6,img);
		   preparedStatement.setString(7,email);
		   preparedStatement.setString(8,group);
		   rs=preparedStatement.executeUpdate();
		   //关闭数据库
		   conn.close();
	 } catch (SQLException e) {
		e.printStackTrace();
	}
	  if(rs==1){
   	   return true;
      }else{
   	   return false;
      }
	 }
		//向公告表插入数据
	 public boolean insertToNotice(String title,String content,String author){
	 int rs = 0;
    DBConn conn=new DBConn();
	 String sql="insert into notice(title,content,author) values(?,?,?)";
	 try {
		PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
		  preparedStatement.setString(1,title);
		   preparedStatement.setString(2,content);
		   preparedStatement.setString(3,author);
		   rs=preparedStatement.executeUpdate();
		   //关闭数据库
		   conn.close();
	 } catch (SQLException e) {
		e.printStackTrace();
	}
	  if(rs==1){
   	   return true;
      }else{
   	   return false;
      }
	 }
	  //管理员修改个人会员的信息
	 public boolean updatePersonInfoByManager(String pwd,String email,String usernumber){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="update user set pwd=?,email=? where usernumber=?";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,pwd);
				   preparedStatement.setString(2,email);
				   preparedStatement.setString(3,usernumber);
				   rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
	 }
	  //管理员修改企业会员的信息
		 public boolean updateComMenInfoByManager(String pwd,String email,String usernumber){
			 int rs = 0;
			    DBConn conn=new DBConn();
				 String sql="update user set pwd=?,email=? where usernumber=?";
				 try {
					PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
					  preparedStatement.setString(1,pwd);
					   preparedStatement.setString(2,email);
					   preparedStatement.setString(3,usernumber);
					   rs=preparedStatement.executeUpdate();
					   //关闭数据库
					   conn.close();
				 } catch (SQLException e) {
					e.printStackTrace();
				}
				  if(rs==1){
			   	   return true;
			      }else{
			   	   return false;
			      }
		 }
		  //管理员修改公告的信息
		 public boolean updateNoticeByManager(String title,String content,String author,String noticeid){
			 int rs = 0;
			    DBConn conn=new DBConn();
				 String sql="update notice set title=?,content=?,author=? where noticeid=?";
				 try {
					PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
					  preparedStatement.setString(1,title);
					   preparedStatement.setString(2,content);
					   preparedStatement.setString(3,author);
					   preparedStatement.setString(4,noticeid);
					   rs=preparedStatement.executeUpdate();
					   //关闭数据库
					   conn.close();
				 } catch (SQLException e) {
					e.printStackTrace();
				}
				  if(rs==1){
			   	   return true;
			      }else{
			   	   return false;
			      }
		 }
		 //管理员修改会员组别的信息
		 public boolean updateGroupNumber(String GroupNumber,String username){
			 int rs = 0;
			 int rs1=0;
			    DBConn conn=new DBConn();
				 String sql="update membergroup set GroupNumber=? where username=?";
				 String sql1="update user set GroupNumber=? where username=?";
				 try {
					PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
					  preparedStatement.setString(1,GroupNumber);
					   preparedStatement.setString(2,username);
					   rs=preparedStatement.executeUpdate();
					   PreparedStatement pS=(PreparedStatement) conn.getCon().prepareStatement(sql1);
					   pS.setString(1,GroupNumber);
					   pS.setString(2,username);
					   rs1=pS.executeUpdate();
					   //关闭数据库 
					   conn.close();
				 } catch (SQLException e) {
					e.printStackTrace();
				}
				  if(rs==1&&rs1==1){
			   	   return true;
			      }else{
			   	   return false;
			      }
		 }
	  //管理员修改参数表的信息
		 public boolean updateAttrInfoBySysId(String sysid,String lenusername,String lenpassword,String upfiletyle,String upfilesize,String loginstyle,String register){
			 int rs = 0;
			    DBConn conn=new DBConn();
				 String sql="update sys_par set lenusername=?,lenpassword=?,upfiletyle=?,upfilesize=?,loginstyle=?,register=? where sysid=?";
				 try {
					PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
					   preparedStatement.setString(1,lenusername);
					   preparedStatement.setString(2,lenpassword);
					   preparedStatement.setString(3,upfiletyle);
					   preparedStatement.setString(4,upfilesize);
					   preparedStatement.setString(5,loginstyle);
					   preparedStatement.setString(6,register);
					   preparedStatement.setString(7,sysid);
					   rs=preparedStatement.executeUpdate();
					   //关闭数据库
					   conn.close();
				 } catch (SQLException e) {
					e.printStackTrace();
				}
				  if(rs==1){
			   	   return true;
			      }else{
			   	   return false;
			      }
		 }
	 //批量删除个人会员个数
	 public boolean deletePersonNumberList(String str){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="delete  from user  where  usernumber=?";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,str);
                rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
	 }
	 //批量删除评论信息个数
	 public boolean deleteCommentList(String str){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="delete  from user_comment  where  comId=?";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,str);
                rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
	 }
	 //批量删除公告信息个数
	 public boolean deleteNoticeList(String str){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="delete  from notice  where  noticeid=?";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,str);
                rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
	 }
	 //插入数据到个人会员表
	 public boolean insertInfoToPersonTable(String username){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="insert  into  userinfo(username)  values(?)";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,username);
             rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      }
	 }
	//插入数据到企业会员表
	 public boolean insertInfoToComMenTable(String username){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="insert  into  enterprise_user(username)  values(?)";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,username);
          rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      } 
	 }
   //修改管理员信息
	 public boolean updateManageInfo(String username,String pwd,String question,String answer,String safecode,String img){
		 int rs = 0;
		    DBConn conn=new DBConn();
			 String sql="update  user set pwd=?,question=?,answer=?,safecode=?,img=? where  username=?";
			 try {
				PreparedStatement preparedStatement=(PreparedStatement) conn.getCon().prepareStatement(sql);
				  preparedStatement.setString(1,pwd);
				  preparedStatement.setString(2,question);
				  preparedStatement.setString(3,answer);
				  preparedStatement.setString(4,safecode);
				  preparedStatement.setString(5,img);
				  preparedStatement.setString(6,username);
       rs=preparedStatement.executeUpdate();
				   //关闭数据库
				   conn.close();
			 } catch (SQLException e) {
				e.printStackTrace();
			}
			  if(rs==1){
		   	   return true;
		      }else{
		   	   return false;
		      } 
	 }
	 //源源写的
	 /**
		 * 商品操作方法
		 * 
		 * @param args
		 */

		// 管理员修改商品的信息
		public boolean updateProductInfoByManager(String productid, String content,
				String needIntegral) {
			int rs = 0;
			DBConn conn = new DBConn();
			String sql = "update goodinfo set Content=?,needIntegral=? where ProductID=?";
			try {
				PreparedStatement preparedStatement = (PreparedStatement) conn
						.getCon().prepareStatement(sql);
				preparedStatement.setString(1, content);
				preparedStatement.setString(2, needIntegral);
				preparedStatement.setString(3, productid);
				rs = preparedStatement.executeUpdate();
				// 关闭数据库
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			if (rs == 1) {
				return true;
			} else {
				return false;
			}
		}
		
		// 根据id删除商品的信息
			public static boolean deleteProductById(String main_id) {
				int rs = 0;
				try {
					Driver driver = new com.mysql.jdbc.Driver();
					DriverManager.registerDriver(driver);
					Connection connection = (Connection) DriverManager
							.getConnection(
									"jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8",
									"root", "usbw");
					String sql = "delete  from goodinfo where id=?";
					PreparedStatement stmt = (PreparedStatement) connection
							.prepareStatement(sql);
					stmt.setString(1, main_id);
					rs = stmt.executeUpdate();
					stmt.close();
					connection.close();
				} catch (Exception e) {
					e.printStackTrace();
				}
				if (rs == 1) {
					return true;
				} else {
					return false;
				}
			}
			
			// 批量删除商品个数
			public boolean deleteProductNumberList(String str) {
				int rs = 0;
				DBConn conn = new DBConn();
				String sql = "delete  from goodinfo  where  id=?";
				try {
					PreparedStatement preparedStatement = (PreparedStatement) conn
							.getCon().prepareStatement(sql);
					preparedStatement.setString(1, str);
					rs = preparedStatement.executeUpdate();
					// 关闭数据库
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				if (rs == 1) {
					return true;
				} else {
					return false;
				}
			}
			
			// 向商品表插入数据
			public boolean insertToGoodInfo(String ProductID, String Version,
					String PType, String Content, String URL_1, Date addTime) {
				int rs = 0;
				DBConn conn = new DBConn();
				String sql = "insert into goodinfo(ProductID,Version,PType,Content,URL_1,addTime) values(?,?,?,?,?,?)";
				try {
					PreparedStatement preparedStatement = (PreparedStatement) conn
							.getCon().prepareStatement(sql);
					preparedStatement.setString(1, ProductID);
					preparedStatement.setString(2, Version);
					preparedStatement.setString(3, PType);
					preparedStatement.setString(4, Content);
					preparedStatement.setString(5, URL_1);
					preparedStatement.setDate(6, addTime);
					
					rs = preparedStatement.executeUpdate();
					// 关闭数据库
					conn.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
				if (rs == 1) {
					return true;
				} else {
					return false;
				}
			}
			
			/**
			 * 点卡操作
			 * @param args
			 */
			
			// 根据cardid删除点卡的信息
					public static boolean deleteCardById(String card_id) {
						int rs = 0;
						try {
							Driver driver = new com.mysql.jdbc.Driver();
							DriverManager.registerDriver(driver);
							Connection connection = (Connection) DriverManager
									.getConnection(
											"jdbc:mysql://www.ccjjltx.cn:3307/numbersystem?useUnicode=true&characterEncoding=utf8",
											"root", "usbw");
							String sql = "delete  from clickcard where CardID=?";
							PreparedStatement stmt = (PreparedStatement) connection
									.prepareStatement(sql);
							stmt.setString(1, card_id);
							rs = stmt.executeUpdate();
							stmt.close();
							connection.close();
						} catch (Exception e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					// 管理员修改点卡的信息
					public boolean updateCardInfoByManager(int CardNumber, String CardPassword, float Money, int Point) {
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "update clickcard set CardPassword=?,Money=?,Point=? where CardNumber=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, CardPassword);
							preparedStatement.setFloat(2, Money);
							preparedStatement.setInt(3, Point);
							preparedStatement.setInt(4, CardNumber);
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					// 向点卡表插入数据
					public boolean insertToClickCard(int CardNumber, String CardPassword,
							float Money, int Point, Date TimeOutDate, int status, int isUse, int isBuy) {
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "insert into clickcard(CardNumber,CardPassword,Money,Point,TimeOutDate,status,"
								+ "isUse,isBuy) values(?,?,?,?,?,?,?,?)";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setInt(1, CardNumber);
							preparedStatement.setString(2, CardPassword);
							preparedStatement.setFloat(3, Money);
							preparedStatement.setInt(4, Point);
							preparedStatement.setDate(5, TimeOutDate);
							preparedStatement.setInt(6, status);
							preparedStatement.setInt(7, isUse);
							preparedStatement.setInt(8, isBuy);
							
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					// 批量删除点卡个数
					public boolean deleteCardNumberList(String str) {
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "delete  from clickcard where CardNumber=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, str);
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					/**
					 * 用户点卡充值
					 * 
					 * @param args
					 */

					// 查询出用户的原有金额
					public Float queryMoneyFromClickCard(String CardNumber) {
						Float oldmoney = null;
						ResultSet rs = null;
						DBConn conn = new DBConn();
						String sql = "select * from clickcard where CardNumber=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, CardNumber);
							rs = preparedStatement.executeQuery();
							while (rs.next()) {
								oldmoney = rs.getFloat("Money");
							}
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						return oldmoney;

					}

					public boolean updateMoneyToClickCard(String CardNumber, float Money) {
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "update clickcard set Money=? where CardNumber=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setFloat(1, Money);
							preparedStatement.setString(2, CardNumber);
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					/**
					 * 获取商品
					 * @param args
					 */
					
					//根据用户名获取CardID
					public static int queryCardIDByUsername(String username){
						int CardID = 0;
						ResultSet rs = null;
						DBConn conn = new DBConn();
						String sql = "select * from user where username=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, username);
							rs = preparedStatement.executeQuery();
							while (rs.next()) {
								CardID = rs.getInt("CardID");
							}
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						return CardID;

					}
					
					//根据得到的CardID获得点卡金额Money
					public static float queryMoneyByCardID(int CardID){
						Float card_money = null;
						ResultSet rs = null;
						DBConn conn = new DBConn();
						String sql = "select * from clickcard where CardID=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setInt(1, CardID);
							rs = preparedStatement.executeQuery();
							while (rs.next()) {
								card_money = rs.getFloat("Money");
							}
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						return card_money;
					}
					
					//根据ProductID获取商品的金额
					public static float queryMoneyByProductID(String ProductID){
						Float oldmoney = null;
						ResultSet rs = null;
						DBConn conn = new DBConn();
						String sql = "select * from goodinfo where ProductID=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, ProductID);
							rs = preparedStatement.executeQuery();
							while (rs.next()) {
								oldmoney = (float) rs.getInt("needIntegral");
							}
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						return oldmoney;
					}
					
					
					public static boolean updateMoneyToClickCard(int CardID, float Money) {
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "update clickcard set Money=? where CardID=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setFloat(1, Money);
							preparedStatement.setInt(2, CardID);
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					/**
					 * 交易明晰
					 * @param args
					 */
					
					public static boolean insertToTransaction(String ProductID, String username){
						int rs = 0;
						DBConn conn = new DBConn();
						String sql = "insert into transaction(ProductID, username) values(?,?)";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, ProductID);
							preparedStatement.setString(2, username);
							rs = preparedStatement.executeUpdate();
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						if (rs == 1) {
							return true;
						} else {
							return false;
						}
					}
					
					public static String queryProductIDByUsername(String username){
						String ProductID = null;
						ResultSet rs = null;
						DBConn conn = new DBConn();
						String sql = "select * from transaction where username=?";
						try {
							PreparedStatement preparedStatement = (PreparedStatement) conn
									.getCon().prepareStatement(sql);
							preparedStatement.setString(1, username);
							rs = preparedStatement.executeQuery();
							while (rs.next()) {
								ProductID = rs.getString("ProductID");
							}
							// 关闭数据库
							conn.close();
						} catch (SQLException e) {
							e.printStackTrace();
						}
						return ProductID;
					}
   public static void main(String[] args){
//	   String str="1";
//	   databaseTool data=new databaseTool();
//		 ResultSet rs=data.selectManageInfo("33");
   }
}
